<?php
header("Content-Type: application/json");
require_once 'db.php';

$data = json_decode(file_get_contents('php://input'), true);

try {
    $stmt = $conn->prepare("
        UPDATE bookings 
        SET status = 1 
        WHERE id = ? 
        AND user_id = ?
        AND status = 0
    ");
    $stmt->bind_param("ii", $data['booking_id'], $data['user_id']);
    $stmt->execute();
    
    if ($stmt->affected_rows > 0) {
        echo json_encode(['status' => 'success']);
    } else {
        echo json_encode(['status' => 'error', 'msg' => '状态更新失败']);
    }
} catch (Exception $e) {
    echo json_encode(['status' => 'error', 'msg' => $e->getMessage()]);
}
?>